<?php

namespace app\common\model;

use think\Model;

/**
 * vod_info模型
 */
class VodInfo extends Model
{

    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'datetime';
    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';
    // 时间字段取出后的默认时间格式
    protected $dateFormat = 'Y-m-d H:i:s';
    // 追加属性
    protected $append = [];

    public function video()
    {
        return $this->belongsTo('Video', 'video_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function videolist()
    {
        return $this->belongsTo('Videolist', 'videolist_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function vod()
    {
        return $this->belongsTo('Vod', 'vod_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /**
     * 新增vodInfo信息
     * @param $videoId
     * @param $videolistId
     * @param $vodId
     * @param $playType
     * @param $codec
     * @param $duration
     * @param $videoSize
     * @param $width
     * @param $hight
     * @param $bitRate
     * @param $frameRate
     * @param $quality
     * @param null $assetId
     * @return array|bool|float|int|mixed|object|\stdClass|null
     */
    public static function addVodInfo($videoId, $videolistId, $vodId, $url, $playType, $codec, $duration, $videoSize, $width, $hight, $bitRate, $frameRate, $quality, $assetId)
    {
        $vodInfo = new self;
        $vodInfo->video_id = $videoId;
        $vodInfo->videolist_id = $videolistId;
        $vodInfo->vod_id = $vodId;
        $vodInfo->url = $url;
        $vodInfo->play_type = $playType;
        $vodInfo->codec = $codec;
        $vodInfo->duration = $duration;
        $vodInfo->video_size = $videoSize;
        $vodInfo->width = $width;
        $vodInfo->hight = $hight;
        $vodInfo->bit_rate = $bitRate;
        $vodInfo->frame_rate = $frameRate;
        $vodInfo->quality = $quality;
        $vodInfo->asset_id = $assetId;
        $vodInfo->save();
        return $vodInfo->id;
    }

    /**
     * 新增vodInfo信息
     * @param $vodId
     * @param $attr
     * @return array|bool|float|int|mixed|object|\stdClass|null
     */
    public static function updateVodInfo($vodId, $attr)
    {
        return self::where(['id' => $vodId])->update($attr);
    }
}
